define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'account/sessions/index' + location.search,
                    add_url: 'account/sessions/add',
                    edit_url: 'account/sessions/edit',
                    del_url: 'account/sessions/del',
                    multi_url: 'account/sessions/multi',
                    import_url: 'account/sessions/import',
                    table: 'account_sessions',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'code', title: __('Code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'status', title: __('Status'), searchList: {"50":__('Status 50')}, formatter: Table.api.formatter.status},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'delete_time', title: __('Delete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'sku_id', title: __('Sku_id')},
                        {field: 'token', title: __('Token'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'duration', title: __('Duration')},
                        {field: 'is_switch_account', title: __('Is_switch_account')},
                        {field: 'account_id', title: __('Account_id')},
                        {field: 'dispatch_mj_number', title: __('Dispatch_mj_number')},
                        {field: 'session_number', title: __('Session_number')},
                        {field: 'status_number', title: __('Status_number')},
                        {field: 'tenant_id', title: __('Tenant_id')},
                        {field: 'active_time', title: __('Active_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'dispatch_channel', title: __('Dispatch_channel'), operate: 'LIKE'},
                        {field: 'ip_limit_cnt', title: __('Ip_limit_cnt')},
                        {field: 'bind_server_name', title: __('Bind_server_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'login_number', title: __('Login_number')},
                        {field: 'swiper_number', title: __('Swiper_number')},
                        {field: 'effect_time', title: __('Effect_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'effect_time2', title: __('Effect_time2'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'status_time', title: __('Status_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'guild_id', title: __('Guild_id'), operate: 'LIKE'},
                        {field: 'channel_id', title: __('Channel_id'), operate: 'LIKE'},
                        {field: 'ip', title: __('Ip'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status_text', title: __('Status_text'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
